package me.zk.practice1.s;

/**
 * @author zhangkai
 * @date 2023/7/6 12:12
 */
public class LS83 {
    public ListNode deleteDuplicates(ListNode head) {

        ListNode node = head;
        while (node != null) {
            if (node.next != null && node.val == node.next.val) {
                node.next = node.next.next;
            } else {
                node = node.next;
            }

        }
        return head;

    }

    public ListNode deleteDuplicates2(ListNode head) {
        if (head == null) {
            return null;
        }
        if (head.next == null) {
            return head;
        }
        if (head.val == head.next.val) {
            head = deleteDuplicates2(head.next);
        } else {
            head.next = deleteDuplicates2(head.next);
        }
        return head;

    }
}
